/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;
import java.util.*;
import javax.swing.table.AbstractTableModel;
import Entities.*;

/**
 *
 * @author Heinz Hernandez
 */
public class PersonTableModel extends AbstractTableModel{

    List<Person> personList;

        String[] headerList = {"ID","NAME","LASTNAME","SSN","BDATE","BPLACE","FOCUS","SPECIALITY","SALARY","GRADUATEAT"};
        Class[] classes = { Long.class, String.class, String.class, String.class, Date.class, String.class, String.class, String.class, Integer.class, String.class };

        public PersonTableModel(List<Person> list) {
            personList = list;
        }

        @Override
        public int getColumnCount() {
            return headerList.length;
        }

        @Override
        public int getRowCount() {
            return personList.size();
        }

        @Override
        public Class<?> getColumnClass(int arg0) {
            // TODO Auto-generated method stub
            return classes[arg0];
        }

        // this method is called to set the value of each cell
        @Override
        public Object getValueAt(int row, int column) {
            Person entity = null;
            entity = personList.get(row);
            switch (column) {
            case 0:
                return entity.getPerId();
            case 1:
                return entity.getPerName();
            case 2:
                return entity.getPerLastName();
            case 3:
                return entity.getPerSsn();
            case 4:
                return entity.getPerBirthDate();
            case 5:
                return entity.getPerBirthPlace();
            case 6:
                return entity.getPerFocus();
            case 7:
                return entity.getPerSpeciality();
            case 8:
                return entity.getPerSalary();
            case 9:
                return entity.getPerGraduateat();
            default:
                return "";
            }
        }

        // This method will be used to display the name of columns
    @Override
        public String getColumnName(int col) {
            return headerList[col];
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            Person entity = null;
            entity = personList.get(row);
            switch (col) {
            case 0:
                entity.setPerId((Long) value);
                break;
            case 1:
                entity.setPerName((String) value);
                break;
            case 2:
                entity.setPerLastName((String) value);
                break;
            case 3:
                entity.setPerSsn((String) value);
                break;
            case 4:
                entity.setPerBirthDate((Date) value);
                break;
            case 5:
                entity.setPerBirthPlace((String) value);
                break;
            case 6:
                entity.setPerFocus((String) value);
                break;
            case 7:
                entity.setPerSpeciality((String) value);
                break;
            case 8:
                entity.setPerSalary((Integer) value);
                break;
            case 9:
                entity.setPerGraduateat((String) value);
                break;
            default:
                break;

            }
            fireTableCellUpdated(row, col);
        }


}

